package com.ruoyi.web.controller.work;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.work.domain.WorkCompanyBank;
import com.ruoyi.work.service.IWorkCompanyBankService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司账号Controller
 * 
 * @author ruoyi
 * @date 2021-12-21
 */
@Controller
@RequestMapping("/work/bank")
public class WorkCompanyBankController extends BaseController
{
    private String prefix = "work/bank";

    @Autowired
    private IWorkCompanyBankService workCompanyBankService;

    @RequiresPermissions("work:bank:view")
    @GetMapping()
    public String bank()
    {
        return prefix + "/bank";
    }

    /**
     * 查询公司账号列表
     */
    @RequiresPermissions("work:bank:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WorkCompanyBank workCompanyBank)
    {
        startPage();
        List<WorkCompanyBank> list = workCompanyBankService.selectWorkCompanyBankList(workCompanyBank);
        return getDataTable(list);
    }

    /**
     * 导出公司账号列表
     */
    @RequiresPermissions("work:bank:export")
    @Log(title = "公司账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WorkCompanyBank workCompanyBank)
    {
        List<WorkCompanyBank> list = workCompanyBankService.selectWorkCompanyBankList(workCompanyBank);
        ExcelUtil<WorkCompanyBank> util = new ExcelUtil<WorkCompanyBank>(WorkCompanyBank.class);
        return util.exportExcel(list, "公司账号数据");
    }

    /**
     * 新增公司账号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司账号
     */
    @RequiresPermissions("work:bank:add")
    @Log(title = "公司账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WorkCompanyBank workCompanyBank)
    {
        return toAjax(workCompanyBankService.insertWorkCompanyBank(workCompanyBank));
    }

    /**
     * 修改公司账号
     */
    @RequiresPermissions("work:bank:edit")
    @GetMapping("/edit/{companyId}")
    public String edit(@PathVariable("companyId") Long companyId, ModelMap mmap)
    {
        WorkCompanyBank workCompanyBank = workCompanyBankService.selectWorkCompanyBankByCompanyId(companyId);
        mmap.put("workCompanyBank", workCompanyBank);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司账号
     */
    @RequiresPermissions("work:bank:edit")
    @Log(title = "公司账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WorkCompanyBank workCompanyBank)
    {
        return toAjax(workCompanyBankService.updateWorkCompanyBank(workCompanyBank));
    }

    /**
     * 删除公司账号
     */
    @RequiresPermissions("work:bank:remove")
    @Log(title = "公司账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(workCompanyBankService.deleteWorkCompanyBankByCompanyIds(ids));
    }
}
